package cn.whuc.spark.operator

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo_filter {
  def main(args: Array[String]): Unit = {
    // 1 创建sparkContext
    val sc: SparkContext = new SparkContext(
      new SparkConf()
        .setMaster("local[*]")
        .setAppName(" ")
    )

    // 2 编写代码
    val rdd1: RDD[String] = sc.textFile("input/apache.log")
    val rdd2: RDD[String] = rdd1.filter(line => {
      val bool: Boolean = line.split(" ")(3).split(":")(0).equals("17/05/2015")
      bool
    }).map(line => {
      val strings: Array[String] = line.split(" ")
      strings(strings.length - 1)
    })

    rdd2.collect().foreach(println)


    // 3 关闭上下文对象
    sc.stop()
  }
}
